﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
	/// <summary>
	/// 数据访问类:T_WorkAgainExam
	/// </summary>
	public partial class T_WorkAgainExam
	{
		public T_WorkAgainExam()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Model.T_WorkAgainExam model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_WorkAgainExam(");
			strSql.Append("ExamID,ExamName,EmployeeID,EmployeeCardNo,EmployeeName,ExamDatetime,Score,TypeCode,TypeName)");
			strSql.Append(" values (");
			strSql.Append("@ExamID,@ExamName,@EmployeeID,@EmployeeCardNo,@EmployeeName,@ExamDatetime,@Score,@TypeCode,@TypeName)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamID", SqlDbType.Int,4),
					new SqlParameter("@ExamName", SqlDbType.NVarChar,100),
					new SqlParameter("@EmployeeID", SqlDbType.Int,4),
					new SqlParameter("@EmployeeCardNo", SqlDbType.NVarChar,50),
					new SqlParameter("@EmployeeName", SqlDbType.NVarChar,50),
					new SqlParameter("@ExamDatetime", SqlDbType.DateTime),
					new SqlParameter("@Score", SqlDbType.Int,4),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.NChar,10)};
			parameters[0].Value = model.ExamID;
			parameters[1].Value = model.ExamName;
			parameters[2].Value = model.EmployeeID;
			parameters[3].Value = model.EmployeeCardNo;
			parameters[4].Value = model.EmployeeName;
			parameters[5].Value = model.ExamDatetime;
			parameters[6].Value = model.Score;
			parameters[7].Value = model.TypeCode;
			parameters[8].Value = model.TypeName;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.T_WorkAgainExam model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_WorkAgainExam set ");
			strSql.Append("ExamID=@ExamID,");
			strSql.Append("ExamName=@ExamName,");
			strSql.Append("EmployeeID=@EmployeeID,");
			strSql.Append("EmployeeCardNo=@EmployeeCardNo,");
			strSql.Append("EmployeeName=@EmployeeName,");
			strSql.Append("ExamDatetime=@ExamDatetime,");
			strSql.Append("Score=@Score,");
			strSql.Append("TypeCode=@TypeCode,");
			strSql.Append("TypeName=@TypeName");
			strSql.Append(" where AgainExamId=@AgainExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamID", SqlDbType.Int,4),
					new SqlParameter("@ExamName", SqlDbType.NVarChar,100),
					new SqlParameter("@EmployeeID", SqlDbType.Int,4),
					new SqlParameter("@EmployeeCardNo", SqlDbType.NVarChar,50),
					new SqlParameter("@EmployeeName", SqlDbType.NVarChar,50),
					new SqlParameter("@ExamDatetime", SqlDbType.DateTime),
					new SqlParameter("@Score", SqlDbType.Int,4),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.NChar,10),
					new SqlParameter("@AgainExamId", SqlDbType.Int,4)};
			parameters[0].Value = model.ExamID;
			parameters[1].Value = model.ExamName;
			parameters[2].Value = model.EmployeeID;
			parameters[3].Value = model.EmployeeCardNo;
			parameters[4].Value = model.EmployeeName;
			parameters[5].Value = model.ExamDatetime;
			parameters[6].Value = model.Score;
			parameters[7].Value = model.TypeCode;
			parameters[8].Value = model.TypeName;
			parameters[9].Value = model.AgainExamId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int AgainExamId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_WorkAgainExam ");
			strSql.Append(" where AgainExamId=@AgainExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@AgainExamId", SqlDbType.Int,4)
			};
			parameters[0].Value = AgainExamId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string AgainExamIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_WorkAgainExam ");
			strSql.Append(" where AgainExamId in ("+AgainExamIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkAgainExam GetModel(int AgainExamId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 AgainExamId,ExamID,ExamName,EmployeeID,EmployeeCardNo,EmployeeName,ExamDatetime,Score,TypeCode,TypeName from T_WorkAgainExam ");
			strSql.Append(" where AgainExamId=@AgainExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@AgainExamId", SqlDbType.Int,4)
			};
			parameters[0].Value = AgainExamId;

			Model.T_WorkAgainExam model=new Model.T_WorkAgainExam();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkAgainExam DataRowToModel(DataRow row)
		{
			Model.T_WorkAgainExam model=new Model.T_WorkAgainExam();
			if (row != null)
			{
				if(row["AgainExamId"]!=null && row["AgainExamId"].ToString()!="")
				{
					model.AgainExamId=int.Parse(row["AgainExamId"].ToString());
				}
				if(row["ExamID"]!=null && row["ExamID"].ToString()!="")
				{
					model.ExamID=int.Parse(row["ExamID"].ToString());
				}
				if(row["ExamName"]!=null)
				{
					model.ExamName=row["ExamName"].ToString();
				}
				if(row["EmployeeID"]!=null && row["EmployeeID"].ToString()!="")
				{
					model.EmployeeID=int.Parse(row["EmployeeID"].ToString());
				}
				if(row["EmployeeCardNo"]!=null)
				{
					model.EmployeeCardNo=row["EmployeeCardNo"].ToString();
				}
				if(row["EmployeeName"]!=null)
				{
					model.EmployeeName=row["EmployeeName"].ToString();
				}
				if(row["ExamDatetime"]!=null && row["ExamDatetime"].ToString()!="")
				{
					model.ExamDatetime=DateTime.Parse(row["ExamDatetime"].ToString());
				}
				if(row["Score"]!=null && row["Score"].ToString()!="")
				{
					model.Score=int.Parse(row["Score"].ToString());
				}
				if(row["TypeCode"]!=null && row["TypeCode"].ToString()!="")
				{
					model.TypeCode=int.Parse(row["TypeCode"].ToString());
				}
				if(row["TypeName"]!=null)
				{
					model.TypeName=row["TypeName"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select AgainExamId,ExamID,ExamName,EmployeeID,EmployeeCardNo,EmployeeName,ExamDatetime,Score,TypeCode,TypeName ");
			strSql.Append(" FROM T_WorkAgainExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" AgainExamId,ExamID,ExamName,EmployeeID,EmployeeCardNo,EmployeeName,ExamDatetime,Score,TypeCode,TypeName ");
			strSql.Append(" FROM T_WorkAgainExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_WorkAgainExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.AgainExamId desc");
			}
			strSql.Append(")AS Row, T.*  from T_WorkAgainExam T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_WorkAgainExam";
			parameters[1].Value = "AgainExamId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

